package com.mvd.app.activity;


import android.Manifest;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.jph.takephoto.app.TakePhoto;
import com.jph.takephoto.app.TakePhotoActivity;
import com.jph.takephoto.compress.CompressConfig;
import com.jph.takephoto.model.TImage;
import com.jph.takephoto.model.TResult;
import com.jph.takephoto.model.TakePhotoOptions;
import com.kongzue.dialog.util.DialogSettings;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.BuildConfig;
import com.mvd.app.R;
import com.mvd.app.ac2021.ErrorMsgActivity;
import com.mvd.app.ac2021.WaiJianItemActivity;
import com.mvd.app.adapter.ContentAdapter2;
import com.mvd.app.api.ApiConfig;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.SystemUtil;
import com.mvd.app.commons.Utils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.BuHeGeModel3;
import com.mvd.app.model.CarItemEndModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.CheckItemModel;
import com.mvd.app.model.CodeListModel;
import com.mvd.app.model.Item_2Model;
import com.mvd.app.model.ItemsModel;
import com.mvd.app.model.MyChoiceModel;
import com.mvd.app.model.OtherWaiJianPhotoModel;
import com.mvd.app.model.OutPhotoItem;
import com.mvd.app.model.PhotoTypeModel;
import com.mvd.app.model.ReportedModel;
import com.mvd.app.model.ReportedModel3;
import com.mvd.app.model.TypeModel;
import com.mvd.app.model.UpdateCarStatusModel;
import com.mvd.app.model.UploadPhotoModel;
import com.mvd.app.model.VideoModel;
import com.mvd.app.model.WaiJainDataModel;
import com.mvd.app.model.WaiJianItemModel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countuptime.CountupView;
import pub.devrel.easypermissions.EasyPermissions;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

import static com.mvd.app.application.BaseApplication.IsFirst;
import static com.mvd.app.application.BaseApplication.WAIJIAN_PHOTO_PREVIEW_LISTS;
import static com.mvd.app.application.BaseApplication.all_checkItemlList;
import static com.mvd.app.application.BaseApplication.checkItemModelList;
import static com.mvd.app.application.BaseApplication.myChoiceModelList;
import static com.mvd.app.application.BaseApplication.myChoiceModelList_waijian_rizhao;
import static com.mvd.app.application.BaseApplication.mycar_checkItemlList;
import static java.lang.System.in;

/**
 *
 */
//外检拍照
public class WaiJianPhotoActivity extends TakePhotoActivity implements AdapterView.OnItemClickListener,
        ApiConfig, EasyPermissions.PermissionCallbacks {

    String tag = "tag";
//    // 相册
//    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
//    private static final int PICK_IMAGE_ACTIVITY_REQUEST_CODE = 200;
//    private static String picFileFullName;

    CarsInforModel carsInforModel;
    @BindView(R.id.ac_waijian_photo_listview)
    ListView acWaijianPhotoListview;
    @BindView(R.id.ac_waijian_btn_buhege2)
    Button acWaijianBtnBuhege2;
    @BindView(R.id.ac_waijian_btn_wancheng2)
    Button acWaijianBtnWancheng2;

    @BindView(R.id.ac_waijian_btn_other_imags)
    Button acWaijianBtnOtherImages;

    @BindView(R.id.ac_waijian_btn_tezhengcanshu)
    Button acWaijianBtntezengcanshu;

    @BindView(R.id.ac_waijian_photo_scrollview)
    ScrollView acWaijianScrollView;
    @BindView(R.id.ac_waijian_tv_jishiqi_time_time)
    TextView acWaijianTvJishiqi;
    @BindView(R.id.ac_waijian_photo_ll_bottom_layout)
    LinearLayout acWaijianPhotoLlBottomLayout;

    private WaiJianPhotoActivity instances = null;
    private String ID = null;//检测车辆ID
    private String carNo = null;//车牌号码
    private String PlateType = null;//号牌种类类型
    private String cartype = null;//车辆类型
    private String PHOTO_TYPE = null;//外检拍照的TYPE上传类型
    private String waijian_chedao = null;//外检车道，检测线代号
    private List<PhotoTypeModel> photoTypeModelList;//照片类型列表

    private int CHECK_MODE = 0;//检测模式 0:外检  1：路试 2：底盘动态
    private String Line = "1";//外检车道
    private String Item_Code = "";//F1外检,R1路试，DC底盘动态
    private WaiJainDataModel waiJainDataModel = new WaiJainDataModel();//外检上传数据model
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    //    BaseApplication.mycar_checkItemlList = new ArrayList<>();//获取当前车辆需要的人工检验项目

    private VideoModel model = new VideoModel();
    private List<Boolean> IsTakePhoto = new ArrayList<>();//当前车辆要检测的项目是否拍照的列表

    TakePhoto takePhoto;
    Uri imageUri;
    int recLen = 0;
    //    Handler handler = new Handler();
//    Runnable runnable = new Runnable() {
//        @Override
//        public void run() {
//            recLen++;
//            if (recLen < 1200) {
//                acWaijianTvJishiqi.setText("项目进行时间：" + recLen + "  秒");
//            }
//            handler.postDelayed(this, 1000);
//        }
//    };
    CountupView mCvCountupViewTest1;
    int gotoTakePhotoCounts = 0;//外检上传自己后台次数
    int gotoTakePhotoCounts2 = 0;//外检上传自己后台次数
    int gotoTakePhotoCounts3 = 0;//平台次数

    static final String[] PERMISSIONS = new String[]{
            Manifest.permission.RECORD_AUDIO,
            Manifest.permission.CAMERA,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    private String my_item_start_time = "", my_item_end_time = "";
    private boolean is_db_data = false;//数据库是否保存数据   false:无   true：有
    List<WaiJianItemModel> books = new ArrayList<>();
    String upload_code_str = "", upload_code_str_500 = "";
    static final String STATE_PHOTO_TYPE = "PHOTO_TYPE";
    static final String STATE_PHOTO_TYPE_huan = "PHOTO_TYPE_huan";
    static final String STATE_typeModel = "typeModel";
    static final String STATE_TypeModel_Position = "TypeModel_Position";

    private WaiJainDataModel waiJainDataModel2 = new WaiJainDataModel();//外检上传数据model
    boolean is_500 = false;

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // 保存用户自定义的状态
        savedInstanceState.putString(STATE_PHOTO_TYPE, PHOTO_TYPE);
        savedInstanceState.putSerializable(STATE_typeModel, typeModel);
        savedInstanceState.putInt(STATE_TypeModel_Position, TypeModel_Position);
        // 调用父类交给系统处理，这样系统能保存视图层次结构状态
        super.onSaveInstanceState(savedInstanceState);
    }

    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // 总是调用超类，以便它可以恢复视图层次超级
        super.onRestoreInstanceState(savedInstanceState);
        // 从已保存的实例中恢复状态成员
        PHOTO_TYPE = savedInstanceState.getString(STATE_PHOTO_TYPE);
        typeModel = (TypeModel) savedInstanceState.getSerializable(STATE_typeModel);
        TypeModel_Position = savedInstanceState.getInt(STATE_TypeModel_Position);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        setContentView(R.layout.activity_wai_jian_photo);
        ButterKnife.bind(this);
        String logStrf = "\n" + "onCreate-----外检拍照---WaiJianPhotoActivity-----" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

        DialogSettings.style = (DialogSettings.STYLE.STYLE_KONGZUE);
        DialogSettings.init();
        if (EasyPermissions.hasPermissions(this, PERMISSIONS)) {//检查是否获取该权限
            UtilsLog.e("zzl=已获取权限");
        } else {
            UtilsLog.e("zzl=meiyou===权限");
            //第二个参数是被拒绝后再次申请该权限的解释
            //第三个参数是请求码
            //第四个参数是要申请的权限
            EasyPermissions.requestPermissions(this, "必要的权限", 0, PERMISSIONS);

        }
        mCvCountupViewTest1 = (CountupView) findViewById(R.id.ac_waijian_tv_jishiqi_cv_CountupViewTest3);
        mCvCountupViewTest1.setTag("test1");
        long time1 = (long) 1000;
        mCvCountupViewTest1.start(time1);

//        handler.postDelayed(runnable, 1000);

//        WAIJIAN_PHOTO_PREVIEW_LISTS = new HashMap<>();
        instances = this;
        waijian_chedao = getIntent().getExtras().getString("CarDetailsActivity_acCarDetailsWaijianchedao",
                "");
        carsInforModel = (CarsInforModel) getIntent().getSerializableExtra
                ("CarDetailsActivity_CarsInforModel");
        UtilsLog.e("carsInforModel=55=" + carsInforModel.toString());
//        carsInforModel = getIntent().getExtras().getParcelable("CarDetailsActivity_CarsInforModel");
        Login_name = getIntent().getExtras().getString("login_w_name", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        UtilsLog.e("Login_name=Login_name=" + Login_name);

//        verifyStoragePermissions(instances);
        //检测车辆ID
        ID = String.valueOf(carsInforModel.getID());
        //车牌号码
        if (!TextUtils.isEmpty(carsInforModel
                .getPlateNO())) {
            carNo = carsInforModel.getPlateNO();
        }
        //号牌类型
        if (!TextUtils.isEmpty(carsInforModel.getPlateType())) {
            PlateType = String.valueOf(carsInforModel.getPlateType());
        }
        //车辆类型
        if (!TextUtils.isEmpty(carsInforModel.getVehicleType())) {
            cartype = String.valueOf(carsInforModel.getVehicleType());
        }
        //获取去图片类型列表
//        getDataPhotoTypeList();

        CHECK_MODE = BaseApplication.JIANCE_MODE;
        UtilsLog.e("WaiJianPhotoActivity---CHECK_MODE==" + CHECK_MODE);
        Line = getIntent().getStringExtra("CarDetailsActivity_Line");
        switch (CHECK_MODE) {
            case 0:
                Item_Code = "F1";
                break;
            case 1:
                Item_Code = "R1";
                break;
            case 2:
                Item_Code = "DC";
                break;
        }
        if (BaseApplication.checkItemModelList != null) {
            String logStr2 = "\n" + "外检--拍照页面-BaseApplication.checkItemModelList" +
                    "\n" + "BaseApplication.checkItemModelList::" + BaseApplication.checkItemModelList.toString() + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
        } else {
            String logStr2 = "\n" + "外检--拍照页面-BaseApplication.checkItemModelList=null" + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
        }
        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
            myChoiceModelList.clear();
        }
        List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
        Item_2Model item_2 = null;
        for (int i = 0; i < BaseApplication.checkItemModelList.size(); i++) {
            item_2 = new Item_2Model();
            item_2.setID(BaseApplication.checkItemModelList.get(i).getID());
            item_2.setCode1(BaseApplication.checkItemModelList.get(i).getCode1());
            item_2.setCode2(BaseApplication.checkItemModelList.get(i).getCode2());
            item_2.setName2(BaseApplication.checkItemModelList.get(i).getName2());
            Item_2Model_list.add(item_2);
        }
        for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
            for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                    Item_2Model_list.remove(j);
                }
            }
        }
//        if (IsFirst) {
        for (int i = 0; i < Item_2Model_list.size(); i++) {
            // UtilsLog.e("Item_2Model_list=11=" + Item_2Model_list.get(i).toString());
            MyChoiceModel model = new MyChoiceModel();
            model.setCode2(Item_2Model_list.get(i).getCode2());
            model.setChecked(true);
            model.setName2(Item_2Model_list.get(i).getName2());
            model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
            model.setCode_values("0");
            myChoiceModelList.add(model);
        }
        for (int i = 0; i < Item_2Model_list.size(); i++) {
            MyChoiceModel model = new MyChoiceModel();
            model.setCode2(Item_2Model_list.get(i).getCode2());
            model.setChecked(true);
            model.setName2(Item_2Model_list.get(i).getName2());
            model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
            model.setCode_values("0");
            myChoiceModelList_waijian.add(model);
        }
//            for (int i = 0; i < myChoiceModelList.size(); i++) {
//                UtilsLog.e("myChoiceModelList=11=" + myChoiceModelList.get(i).toString());
//            }
        getMyCarItems();
//        }

        init();
        getOutPhotoItem();

        BaseApplication.BaseApplication_buHeGeModel3List = new ArrayList<>();
//        appendCode2AndValues();


//        books = WaiJianItemModel.listAll(WaiJianItemModel.class);
//        if (books != null && books.size() > 0) {
//            is_db_data = true;
//            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询----不为空==" + books.toString());
//            for (int i = 0; i < books.size(); i++) {
////                WaiJianItemModel.delete(books.get(i));
//            }
//        } else {
//            is_db_data = false;
//            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询----空==");
//        }
    }

    //获取所有人工检验项目接口
    private void getGET_ALL_ITEMList() {
        String url = "";
        url = GET_ALL_ITEM;
        String logStr = "\n" + "获取所有人工检验项目接口----" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) +
                url + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getGET_ALL_ITEMList---url==" + SharedPreferencesUtils.getIP(instances) + url);
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + url).tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
//                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
//                        UtilsLog.e("getGET_ALL_ITEMList-result==" + result);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("getGET_ALL_ITEMList-newResult==" + newResult);
//                        String logStr = "\n" + "获取所有人工检验项目接口----onSuccess" + "\n" + "result::" + response.body() + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            List<CheckItemModel> checkItemModelList2 = new ArrayList<>();
                            myChoiceModelList_waijian = new ArrayList<>();
                            checkItemModelList = new ArrayList<CheckItemModel>();
                            checkItemModelList = JsonUtil.stringToArray(newResult, CheckItemModel[].class);
                            checkItemModelList2 = JsonUtil.stringToArray(newResult, CheckItemModel[].class);

//                            myChoiceModelList_waijian = new ArrayList<>();
                            List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                            Item_2Model item_2 = null;
                            if (checkItemModelList2 != null &&
                                    checkItemModelList2.size() > 0) {
                                for (int i = 0; i < checkItemModelList2.size(); i++) {
                                    item_2 = new Item_2Model();
                                    item_2.setID(checkItemModelList2.get(i).getID());
                                    item_2.setCode1(checkItemModelList2.get(i).getCode1());
                                    item_2.setCode2(checkItemModelList2.get(i).getCode2());
                                    item_2.setName2(checkItemModelList2.get(i).getName2());
                                    Item_2Model_list.add(item_2);
                                }
                                for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                    for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                        if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                                            Item_2Model_list.remove(j);
                                        }
                                    }
                                }
                                for (int i = 0; i < Item_2Model_list.size(); i++) {
                                    MyChoiceModel model = new MyChoiceModel();
                                    model.setCode2(Item_2Model_list.get(i).getCode2());
                                    model.setChecked(true);
                                    model.setName2(Item_2Model_list.get(i).getName2());
                                    model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                                    model.setCode_values("0");
                                    myChoiceModelList_waijian.add(model);
                                }
                            } else {
                                Toast.makeText(instances, "获取所有人工检测项目内容失败，请重试",
                                        Toast.LENGTH_LONG).show();
                            }


                        } else {
//                            Toast.makeText(instances, getResources().getString(R.string.network_error),
// Toast.LENGTH_LONG).show();
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
//                        CommonUtils.hideLoadingDialog(instances);
                        UtilsLog.e("getGET_ALL_ITEMList-onError==" + response.body());
                        String logStr = "\n" + "获取所有人工检验项目接口----onError" + "\n" + "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Toast.makeText(WaiJianPhotoActivity.this, getResources().getString(R.string.services_error), Toast
                                .LENGTH_LONG).show();
                    }
                });
    }

    void bb() {
        getGET_ALL_ITEMList();
        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
            myChoiceModelList.clear();
        }
//        myChoiceModelList_waijian = new ArrayList<>();
        List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
        Item_2Model item_2 = null;
        if (BaseApplication.checkItemModelList != null &&
                BaseApplication.checkItemModelList.size() > 0) {
            for (int i = 0; i < BaseApplication.checkItemModelList.size(); i++) {
                item_2 = new Item_2Model();
                item_2.setID(BaseApplication.checkItemModelList.get(i).getID());
                item_2.setCode1(BaseApplication.checkItemModelList.get(i).getCode1());
                item_2.setCode2(BaseApplication.checkItemModelList.get(i).getCode2());
                item_2.setName2(BaseApplication.checkItemModelList.get(i).getName2());
                Item_2Model_list.add(item_2);
            }
            for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                    if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                        Item_2Model_list.remove(j);
                    }
                }
            }
            for (int i = 0; i < Item_2Model_list.size(); i++) {
                // UtilsLog.e("Item_2Model_list=11=" + Item_2Model_list.get(i).toString());
                MyChoiceModel model = new MyChoiceModel();
                model.setCode2(Item_2Model_list.get(i).getCode2());
                model.setChecked(true);
                model.setName2(Item_2Model_list.get(i).getName2());
                model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                model.setCode_values("0");
                myChoiceModelList.add(model);
            }
        } else {

        }
        getMyCarItems();
//        if (myChoiceModelList_waijian != null && myChoiceModelList_waijian.size() > 0) {
//            for (int i = 0; i < myChoiceModelList_waijian.size(); i++) {
////                UtilsLog.e("看这个==myChoiceModelList_waijian==" + myChoiceModelList_waijian.get(i).toString());
//            }
//        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        // 将结果转发给 EasyPermissions
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
        Log.e("tag", "onRequestPermissionsResult:" + "== requestCode:" + requestCode +
                "===permissions==" + permissions.length +
                "===grantResults==" + grantResults.length);
    }

    @Override
    protected void onResume() {
        super.onResume();
        bb();
        books = WaiJianItemModel.listAll(WaiJianItemModel.class);
        if (books != null && books.size() > 0) {
            is_db_data = true;
            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询----不为空==" + books.toString());
            for (int i = 0; i < books.size(); i++) {
//                WaiJianItemModel.delete(books.get(i));
            }
        } else {
            is_db_data = false;
            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询----空==");
        }
    }

    @Override
    public void takeCancel() {
        super.takeCancel();
    }

    @Override
    public void takeFail(TResult result, String msg) {
        super.takeFail(result, msg);
        Log.e("photo", "拍照失败==" + msg);
        String logStr = "\n" + "外检项目拍照----拍照失败==" + "\n" + msg;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        ArrayList<TImage> images = result.getImages();
        if (images != null && images.size() > 0) {
            String photo_file_path = images.get(0).getCompressPath();
            String photo_file_path2 = images.get(0).getOriginalPath();
            Log.e("photo", "拍照失败--path==" + photo_file_path);
            Log.e("photo", "拍照失败--path=22=" + photo_file_path2);
        }
    }

    //    String photo_file_path;
    String photo_file_path_OriginalPath;
    int FLAG = 1;//0:拍照   1：相册
    private List<String> flagImagesUrls = new ArrayList<>();
    private List<Integer> flagImagesUrlsPosition = new ArrayList<>();

    @Override
    public void takeSuccess(TResult result) {
        super.takeSuccess(result);
        Log.e("photo", "111111111111");
        if (result != null) {
//            showImg(result.getImages());
            ArrayList<TImage> images = result.getImages();
            if (images != null && images.size() > 0) {
                //压缩后的图片路径，不压缩为null
//                photo_file_path = images.get(0).getCompressPath();
                Log.e("photo", "拍照成功--path=111=" + images.get(0).getOriginalPath());
                Log.e("photo", "拍照成功--path=Environment=" + Environment.getExternalStorageDirectory());
                ///storage/emulated/0
                if (FLAG == 1) {
                    //拍照
                    if (SystemUtil.getSystemModel().contains("GIONEE") || SystemUtil.getSystemModel().contains("gionee")) {
                        //金立手机的路线
                        photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
                                .getOriginalPath().replace("my_images/", "");
                        Log.e("photo", "拍照成功-金立手机-path=22=" + photo_file_path_OriginalPath);
                    } else {
                        //其他手机
                        /***
                         * @question 拍照返回的照片的路径处理
                         * @method 有的手机返回的照片带有/storage/emulated/0，
                         * @method 有的不带，所以需要分别处理
                         * @import 找个地方划重点，考试要考的，TDM CD
                         */
                        if (images.get(0).getOriginalPath().contains("storage/emulated")) {
                            photo_file_path_OriginalPath = images.get(0).getOriginalPath().replace("my_images/", "");
                        } else {
                            photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
                                    .getOriginalPath().replace("my_images/", "");
                        }
//                    photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
//                            .getOriginalPath().replace("my_images/", "");
                        Log.e("photo", "拍照成功--path=22=" + photo_file_path_OriginalPath);
                    }
                    try {
                        FileInputStream in = new FileInputStream(photo_file_path_OriginalPath);
                        Bitmap bitmap = BitmapFactory.decodeStream(in);
                        MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "", "");
                        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                        Uri uri = Uri.fromFile(new File("/sdcard/image.jpg"));
                        intent.setData(uri);
                        instances.sendBroadcast(intent);
                    } catch (FileNotFoundException e) {
                        String ee = e.getMessage() + "===" + e.getLocalizedMessage() + "===" + e.getCause() + "===" + e.toString();
                        Log.e("photo", "拍照成功--通知相册刷新失败=" + ee);
                        e.printStackTrace();
                    }
                } else {
                    //相册
                    photo_file_path_OriginalPath = images.get(0)
                            .getOriginalPath().replace("my_images/", "");
                    Log.e("photo", "相册--path=2234343434=" + photo_file_path_OriginalPath);
                }
//                //原图片的路径
//                photo_file_path_OriginalPath = Environment.getExternalStorageDirectory() + images.get(0)
//                        .getOriginalPath().replace("my_images/", "");
//                Log.e("photo", "拍照成功--path=22=" + photo_file_path_OriginalPath);
                if (!TextUtils.isEmpty(photo_file_path_OriginalPath)) {
//                    Log.e("photo", "拍照成功--path=33=" + img_imageUri_path);
//                    if (SharedPreferencesUtils.getPhotoClipping(instances)) {
//                        //拍照需要编辑的
//                        Intent intent = new Intent(instances, WaiRotatePhotoActivity.class);
//                        intent.putExtra("wa_rotate_img", photo_file_path_OriginalPath);
//                        startActivityForResult(intent, 917);
//                    } else {
                    //拍照不需要编辑的
                    Luban.with(instances)
                            .load(new File(photo_file_path_OriginalPath))                     //传人要压缩的图片
                            .setCompressListener(new OnCompressListener() { //设置回调
                                @Override
                                public void onStart() {
                                    // TODO 压缩开始前调用，可以在方法内启动 loading UI
                                }

                                @Override
                                public void onSuccess(File file) {
                                    // TODO 压缩成功后调用，返回压缩后的图片文件
                                    Log.e("photo", "压缩成功后调用");
                                    //拍照压缩后上传
//                                    getData(file,picFileFullName);
                                    getData(file, photo_file_path_OriginalPath);
                                }

                                @Override
                                public void onError(Throwable e) {
                                    // TODO 当压缩过程出现问题时调用
                                    Toast.makeText(instances, "图片压缩出现问题，请重试", Toast.LENGTH_LONG).show();
                                }
                            }).launch();    //启动压缩
                }
//                }
            }
        }
    }


    @OnClick({
            R.id.ac_waijian_btn_buhege2, R.id.ac_waijian_btn_wancheng2,
            R.id.ac_waijian_btn_other_imags, R.id.ac_waijian_btn_tezhengcanshu
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_waijian_btn_tezhengcanshu:
                //特征参数
                Intent intent_te = new Intent(instances, WaiJianItemActivity.class);
                intent_te.putExtra("CarDetailsActivity_CarsInforModel", carsInforModel);
                intent_te.putExtra("CarDetailsActivity_Line", waijian_chedao);
                intent_te.putExtra("login_w_name", Login_name);
                intent_te.putExtra("login_IDNumber", login_IDNumber);
                startActivity(intent_te);
                break;
            case R.id.ac_waijian_btn_wancheng2:
                //外检完成
                String logStr = "\n" + "点击外检完成按钮--111-";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                CommonUtils.showLoadingDialog(instances, "加载中...");
                waiJainDataModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                waiJainDataModel.setGUID(carsInforModel.getGUID());
                waiJainDataModel.setElectronicHandbrake(carsInforModel.getElectronicHandbrake());
                waiJainDataModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(this));
                waiJainDataModel.setBrakeForce(carsInforModel.getBrakeForce());
//                waiJainDataModel.setPlateNO(carsInforModel.getPlateNO());
                waiJainDataModel.setPlateNO(carsInforModel.getPlateNO());
                waiJainDataModel.setTimes(carsInforModel.getTimes());
                waiJainDataModel.setAirAdmission(carsInforModel.getAirAdmission());

                waiJainDataModel.setAppearanceInspector(Login_name);//检测员名字，汉字
                waiJainDataModel.setAppearanceNo(login_IDNumber);

                waiJainDataModel.setApprovedLoad(carsInforModel.getApprovedLoad());
                waiJainDataModel.setArea(carsInforModel.getArea());
                waiJainDataModel.setBodyColor(carsInforModel.getBodyColor());
                waiJainDataModel.setBrand(carsInforModel.getBrand());
                waiJainDataModel.setCarBodyType(carsInforModel.getCarBodyType());
                waiJainDataModel.setCarID(carsInforModel.getCarID());
                waiJainDataModel.setCarModel(carsInforModel.getCarModel());
                waiJainDataModel.setCarTypeLevel(carsInforModel.getCarTypeLevel());
                waiJainDataModel.setCategory(carsInforModel.getCategory());
                waiJainDataModel.setCentralAxle(carsInforModel.getCentralAxle());
                waiJainDataModel.setCode(carsInforModel.getCode());
                waiJainDataModel.setCombCarNO(carsInforModel.getCombCarNO());
                waiJainDataModel.setCurbWeight(carsInforModel.getCurbWeight());
                waiJainDataModel.setDetectDate(carsInforModel.getDetectDate());
                waiJainDataModel.setDetectionCategory(carsInforModel.getDetectionCategory());
                waiJainDataModel.setDetectionStatus(carsInforModel.getDetectionStatus());
                waiJainDataModel.setDisplacement(carsInforModel.getDisplacement());
                waiJainDataModel.setDriveAxle(carsInforModel.getDriveAxle());
                waiJainDataModel.setDriverAxleWeight(carsInforModel.getDriverAxleWeight());
                waiJainDataModel.setDriverTypeName(carsInforModel.getDriverTypeName());
                waiJainDataModel.setDriverType(carsInforModel.getDriverType());
                waiJainDataModel.setPlateType(carsInforModel.getPlateType());
                waiJainDataModel.setItemcode(Item_Code);
                waiJainDataModel.setLine(Line);
                waiJainDataModel.setMainAxis(carsInforModel.getMainAxis());
                waiJainDataModel.setParkingAxle(carsInforModel.getParkingAxle());
                waiJainDataModel.setEngineNO(carsInforModel.getEngineNO());
                waiJainDataModel.setFuelType(carsInforModel.getFuelType());
                waiJainDataModel.setPlateTypeName(carsInforModel.getPlateTypeName());
                waiJainDataModel.setPlatformSN(carsInforModel.getPlatformSN());
                waiJainDataModel.setQueueID(carsInforModel.getQueueID());
                waiJainDataModel.setSN(carsInforModel.getSN());
                waiJainDataModel.setStatus(carsInforModel.getStatus());
                waiJainDataModel.setTest_times(carsInforModel.getTimes());
                waiJainDataModel.setType(carsInforModel.getType());
                waiJainDataModel.setVIN(carsInforModel.getVIN());
                waiJainDataModel.setOutlineHeight(carsInforModel.getOutlineHeight());
                waiJainDataModel.setOutlineLength(carsInforModel.getOutlineLength());
                waiJainDataModel.setOutlineWidth(carsInforModel.getOutlineWidth());
                waiJainDataModel.setStart_Time(BaseApplication.W_ItemStart_time);
                waiJainDataModel.setFinish_Time(DateUtil.currentTime2());

//                appendCode2AndValues();

                model.setItemcode(Item_Code);
                model.setLine(Line);
                model.setPlateNO(carsInforModel.getPlateNO());
                model.setPlateType(carsInforModel.getPlateType());
                model.setPlatformSN(carsInforModel.getPlatformSN());
                model.setTest_times(carsInforModel.getTimes());

                if (CommonUtils.isOnline(instances)) {
                    //上传平台的数据
                    waiJainDataModel.setDataType("F1");
                    uploadPlatformData_w(waiJainDataModel);

//                    Handler handler = new Handler();
//                    handler.postDelayed(new Runnable() {
//                        @Override
//                        public void run() {
//                            getDataWaiJainEnd("");
//                        }
//                    }, 1500);//后执行Runnable中的run方法

//                        getDataReportData();

                    model.setDetectionItemStartDate(BaseApplication.W_ItemStart_time);
                    model.setDetectionItemEndDate(BaseApplication.W_ItemEnd_time);
                    model.setDetectionID(String.valueOf(carsInforModel.getID()));
                    uploadVideo(model);
//                        String logStr33 = "\n" + "点击外检完成按钮--333-";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr33.getBytes());
                    //让按钮变成不可点击
//                        acWaijianBtnWancheng2.setEnabled(false);
//                        getDataReportData();
                } else {
                    Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
                            .LENGTH_LONG).show();
                }

//                finish();
                String logStr22 = "\n" + "点击外检完成按钮--222-";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr22.getBytes());
                break;
            case R.id.ac_waijian_btn_buhege2:
                String logStr2 = "\n" + "外检不合格项目按钮点击" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                //不合格项目录入
//                Intent intent = new Intent(WaiJianPhotoActivity.this, DisqualificationActivity.class);
//                intent.putExtra("buhege_flag", 0);//不合格项目跳转 0：外检 1：底盘动态
//                intent.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
//                startActivity(intent);
                Intent intent_2 = new Intent(WaiJianPhotoActivity.this, com.mvd.app.ac2021.WaiJianResultActivity.class);
                intent_2.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
//                startActivity(intent_2);
                startActivityForResult(intent_2, 500);
                break;
            case R.id.ac_waijian_btn_other_imags:
                String logStr3 = "\n" + "外检-其他拍照照片按钮点击" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
                Intent intent_3 = new Intent(WaiJianPhotoActivity.this, OtherWaiJianPhotoActivity.class);
                startActivityForResult(intent_3, 404);
                break;
        }
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            switch (requestCode) {
                case 500:
                    List<CheckItemModel> list2 = (List<CheckItemModel>) data.getSerializableExtra("waiJianPhoto_buhege_List");
                    List<MyChoiceModel> waiJianPhoto_List = new ArrayList<>();//Code2选择的列表
                    if (list2 != null && list2.size() > 0) {
                        is_500 = true;
                        List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                        Item_2Model item_2 = null;
                        for (int i = 0; i < list2.size(); i++) {
                            item_2 = new Item_2Model();
                            item_2.setID(list2.get(i).getID());
                            item_2.setCode1(list2.get(i).getCode1());
                            item_2.setCode2(list2.get(i).getCode2());
                            item_2.setName2(list2.get(i).getName2());
                            item_2.setFlag(list2.get(i).getFlag());
                            Item_2Model_list.add(item_2);
                        }
                        for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                            for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                                    Item_2Model_list.remove(j);
                                }
                            }
                        }

                        for (int i = 0; i < Item_2Model_list.size(); i++) {
                            MyChoiceModel model = new MyChoiceModel();
                            model.setCode2(Item_2Model_list.get(i).getCode2());
                            model.setChecked(true);
                            model.setName2(Item_2Model_list.get(i).getName2());
                            model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                            model.setCode_values(Item_2Model_list.get(i).getFlag());
                            waiJianPhoto_List.add(model);
                        }
                        upload_code_str_500 = "";
                        for (int i = 0; i < waiJianPhoto_List.size(); i++) {
                            upload_code_str_500 = upload_code_str_500 + "\"" + waiJianPhoto_List.get(i).getCode_key() + "\""
                                    + ":" + "\"" + waiJianPhoto_List.get(i).getCode_values() + "\"" + ",";
                        }
                        if (upload_code_str_500.length() > 0) {
                            upload_code_str_500 = upload_code_str_500.substring(0, upload_code_str_500.length() - 1);
                        }
                        UtilsLog.e("list2" + list2.toString());
                    } else {
                        UtilsLog.e("list2====nulll==");
                    }
                    UtilsLog.e("list2====upload_code_str==" + upload_code_str_500);
                    String logStrfw = "\n" + "onActivityResult---500---upload_code_str_500" +
                            "\n" + "upload_code_str::" + upload_code_str_500;
                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                    break;
                case 404:
                    List<OtherWaiJianPhotoModel> list = (List<OtherWaiJianPhotoModel>) data.getSerializableExtra("othet_waijian_photo");
                    String logStr3 = "\n" + "外检-其他拍照照片按钮点击--onActivityResult" + "\n" +
                            "list:" + list.toString() + "\n";
                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
//                    if (list != null && list.size() > 0 && typeModelListAdapter != null && typeModelListAdapter.size() > 0) {
                    //去掉可能重复的
//                        for (int i = 0; i < typeModelListAdapter.size(); i++) {
//                            for (int j = 0; j < list.size(); j++) {
//                                if ((list.get(j).getName()).equals(typeModelListAdapter.get(i).getName())) {
//                                    typeModelListAdapter.remove(i);
//                                }
//                            }
//                        }
                    if (list != null && list.size() > 0) {
                        //添加新选择的外检拍照
                        TypeModel typeModel = null;
                        for (int j = 0; j < list.size(); j++) {
                            typeModel = new TypeModel();
                            typeModel.setName(list.get(j).getName());
                            typeModel.setCode(list.get(j).getCode());
                            typeModelListAdapter.add(typeModel);
                        }
                        //重新适配listview
                        contentAdapter2 = new ContentAdapter2(instances, typeModelListAdapter,
                                mListener, instances);
                        acWaijianPhotoListview.setAdapter(contentAdapter2);
                        setListViewHeightBasedONChildren(acWaijianPhotoListview);
                    }
                    break;
            }
        }
    }

    private void getData(File file, String file_name) {
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(instances))) {
            if (CommonUtils.isOnline(instances)) {
                getDataUploadPhoto(file, file_name);
//                getDataUploadPhoto2(file, file_name);
            } else {
                Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
                        .LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(this, "请设置IP与端口号", Toast.LENGTH_LONG).show();
        }
    }

    //上传照片
    private void getDataUploadPhoto(final File file, final String file_name) {
        Log.e("photo", "6666666");
        String str = "QueueID:" + carsInforModel.getQueueID() + "\n" +
                "GUID:" + carsInforModel.getGUID() + "\n" +
                "Times:" + carsInforModel.getTimes() + "\n" +
                "PlatformSN:" + carsInforModel.getPlatformSN() + "\n" +
                "SN:" + carsInforModel.getSN() + "\n" +
                "PhotoDate:" + DateUtil.currentTime2() + "\n" +
                "PhotoType:" + PHOTO_TYPE + "\n" +
                "Type:" + carsInforModel.getType() + "\n" +
                "CarNO:" + carsInforModel.getPlateNO() + "\n" +
                "PlateType:" + carsInforModel.getPlateType() + "\n" +
                "ItemCode:" + "F1" + "\n" +
                "Line:" + waijian_chedao + "\n" +
                "VIN:" + carsInforModel.getVIN() + "\n" +
                "AppearanceInspector:" + Login_name + "\n" +
                "FileType:" + "jpg" + "\n";
        UtilsLog.e("安检getDataUploadPhoto---json==" + str);

        String logStr = "\n" + "安检---外检上传照片---json==" +
                "\n" + "json::" + str + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataUploadPhoto---url==" + SharedPreferencesUtils.getIP(instances) + UPLOAD_PHOTO);
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + UPLOAD_PHOTO).tag(instances)
                .params("AppearanceInspector", Login_name)
                //guid
                .params("QueueID", carsInforModel.getQueueID())
                //guid
                .params("GUID", carsInforModel.getGUID())
                //次数
                .params("Times", carsInforModel.getTimes())
                //PlatformSN
                .params("PlatformSN", carsInforModel.getPlatformSN())
                //SN
                .params("SN", carsInforModel.getSN())
                //拍摄时间
                .params("PhotoDate", DateUtil.currentTime2())
                //照片类型-拍的哪里的照片，位置
//                .params("PhotoType", getPlatformCode(PHOTO_TYPE))
                .params("PhotoType", PHOTO_TYPE)
                //车辆类型
                .params("Type", carsInforModel.getType())
                //车牌号码，两个拼起来的
                .params("CarNO", carNo)
                //号牌类型
                .params("PlateType", carsInforModel.getPlateType())
                //拍照code F1表示外检
                .params("ItemCode", "F1")
                //外检车道，检测线代号
                .params("Line", waijian_chedao)
                //车辆识别代码
                .params("VIN", carsInforModel.getVIN())
                .params("FileType", "jpg")
//                .params("FileType", FileUtils.getExtensionName(file.getName()))
                //照片
                .params("zp", file)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");

                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataUploadPhoto-result==" + result);

                        String logStr = "\n" + "外检上传照片--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        UtilsLog.e("response.headers()-result==" + response.headers());
//                        photo_result(PHOTO_TYPE);
//                        if (PHOTO_TYPE != null) {
//                            WAIJIAN_PHOTO_PREVIEW_LISTS.put(Integer.parseInt(PHOTO_TYPE), file);
//                        }
//                        WAIJIAN_PHOTO_PREVIEW_LISTS.put(Integer.parseInt(PHOTO_TYPE), file);
                        if (!TextUtils.isEmpty(result) && !"[[]]".equals(result) && !"[{}]".equals(result)
                                && !"[]".equals(result)) {
//                            String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\",
//                                    "");
//                            UtilsLog.e("getDataUploadPhoto-newResult==" + newResult);
                            if (result.contains("ok") || result.contains("OK")) {
                                try {
                                    if (!TextUtils.isEmpty(file_name)) {
                                        CommonUtils.DeleteImage(instances, file_name);
                                        String[] str_photo_path = file_name.split("Pictures");

                                        UtilsLog.e("str_photo_path[0]===" + str_photo_path[0]);
                                        UtilsLog.e("str_photo_path[1]===" + str_photo_path[1]);
                                        com.mvd.app.commons.FileUtils.deleteDirectory(Environment
                                                .getExternalStorageDirectory() + "/Pictures" +
                                                str_photo_path[1]);
                                    } else {
                                        String logStr2 = "\n" + "外检上传照片--没有获取到即将删除的图片路径" + "\n";
                                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE,
                                                logStr2.getBytes());
                                        UtilsLog.e("getDataUploadPhoto==没有获取到即将删除的图片路径");
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                Toast.makeText(instances, "上传成功", Toast.LENGTH_LONG).show();
                                typeModel.setColor(1);
                                typeModelListAdapter.set(TypeModel_Position, typeModel);
                                contentAdapter2.notifyDataSetChanged();
                            } else {
                                String logStr2 = "\n" + "外检上传照片--失败" +
                                        "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                        UPLOAD_PHOTO + "\n" + "result:" + response.body();
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                Toast.makeText(instances, "上传失败，请重新拍照", Toast.LENGTH_LONG).show();
                            }
                        } else {
                            String logStr3 = "\n" + "外检上传照片--失败" +
                                    "\n" + "data::" + "没有数据" + "\n" + "result:" + response.body();
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
                            UtilsLog.e("getDataUploadPhoto-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataUploadPhoto-onError==" + response.body());
                        UtilsLog.e("getDataUploadPhoto-onError==" + response.getException());
                        String logStr = "\n" + "外检上传照片-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body() + "\n" +
                                response.getException() + "\n" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);

                        Toast.makeText(instances, "上传照片失败，请重试", Toast.LENGTH_LONG).show();
                    }
                });
    }

    //上传照片
    private void getDataUploadPhoto2(final File file, final String file_name) {
        UtilsLog.e("getDataUploadPhoto2---url==" + SharedPreferencesUtils.getIP(instances) + UPLOAD_PHOTO);
        UploadPhotoModel model = new UploadPhotoModel();
        model.setTimes(carsInforModel.getTimes());
        model.setSN(carsInforModel.getSN());
        model.setCarNO(carsInforModel.getPlateNO());
        model.setFileType("jpg");
        model.setGUID(carsInforModel.getGUID());
        model.setItemCode("F1");
        model.setLine(waijian_chedao);
        model.setPhotoDate(DateUtil.currentTime2());
        model.setPlateType(carsInforModel.getPlateType());
        model.setPlatformSN(carsInforModel.getPlatformSN());
        model.setQueueID(carsInforModel.getQueueID());
        model.setType(carsInforModel.getType());
        model.setVIN(carsInforModel.getVIN());
        model.setZp(CommonUtils.imageToBase64(file));
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "\n" + "getDataUploadPhoto2--外检上传照片--参数" +
                "\n" + "json:" + jsonStr;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + UPLOAD_PHOTO).tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataUploadPhoto-result==" + result);
                        String logStr = "\n" + "getDataUploadPhoto2--外检上传照片--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        WAIJIAN_PHOTO_PREVIEW_LISTS.put(Integer.parseInt(PHOTO_TYPE), file);
                        if (!TextUtils.isEmpty(result) && !"[[]]".equals(result) && !"[{}]".equals(result)
                                && !"[]".equals(result)) {
                            if (result.contains("ok") || result.contains("OK")) {
                                Toast.makeText(instances, "上传成功", Toast.LENGTH_LONG).show();
                                typeModel.setColor(1);
                                typeModelListAdapter.set(TypeModel_Position, typeModel);
                                contentAdapter2.notifyDataSetChanged();
                            } else {
                                String logStr2 = "\n" + "getDataUploadPhoto2--外检上传照片--失败" +
                                        "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                        UPLOAD_PHOTO + "\n" + "result:" + response.body();
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                Toast.makeText(instances, "上传失败，请重新拍照", Toast.LENGTH_LONG).show();
                            }
                        } else {
                            String logStr3 = "\n" + "getDataUploadPhoto2外检上传照片--失败" +
                                    "\n" + "data::" + "没有数据" + "\n" + "result:" + response.body();
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
                            UtilsLog.e("getDataUploadPhoto2-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataUploadPhoto2-onError==" + response.body());
                        UtilsLog.e("getDataUploadPhoto2-onError==" + response.getException());
                        String logStr = "\n" + "getDataUploadPhoto2外检上传照片-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getFileIP(instances) +
                                UPLOAD_PHOTO + "\n" + "result:" + response.body() + "\n" +
                                response.getException() + "\n" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);

                        Toast.makeText(instances, "上传照片失败，请重试", Toast.LENGTH_LONG).show();
                    }
                });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
        mCvCountupViewTest1.stop();
    }

    //外检检测结束
    String getDataWaiJainEnd_upjson_url;

    private void getDataWaiJainEnd(String endTime) {
        CarItemEndModel carItemStartModel = new CarItemEndModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
        carItemStartModel.setSN(carsInforModel.getSN());
        carItemStartModel.setTimes(carsInforModel.getTimes());
        carItemStartModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(this));
        carItemStartModel.setItemCode(Item_Code);
        BaseApplication.W_ItemEnd_time = "";
        BaseApplication.W_ItemEnd_time = DateUtil.currentTime2();
        my_item_end_time = BaseApplication.W_ItemEnd_time;
        carItemStartModel.setDetectionItemEndDate(BaseApplication.W_ItemEnd_time);
//        carItemStartModel.setDetectionItemEndDate(endTime);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
//        String upjson_url = "{[" + jsonStr.substring(1, jsonStr.length() - 1) + "]}";
        getDataWaiJainEnd_upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";
        String logStr = "\n" + "外检项目结束--参数" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) + "" +
                ITEM_END + "\n" + "JSON::" + getDataWaiJainEnd_upjson_url +
                "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainEnd---jsonStr==" + getDataWaiJainEnd_upjson_url);
        UtilsLog.e("getDataWaiJainEnd---url==" + SharedPreferencesUtils.getIP(this) + ITEM_END);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_END).tag(this)
                .upJson(getDataWaiJainEnd_upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("getDataWaiJainEnd-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("getDataWaiJainEnd-newResult==" + newResult);
                        String logStr = "\n" + "外检项目结束--请求成功" + "\n" + "URL::" +
                                SharedPreferencesUtils.getIP(instances) + "" +
                                ITEM_END + "\n" + "JSON::" + getDataWaiJainEnd_upjson_url +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (result.contains("ok") || result.contains("OK")) {
//                            Toast.makeText(instances, "外检项目完成", Toast
//                                    .LENGTH_LONG).show();
////                            EndAllItem(String.valueOf(carsInforModel.getID()));
//                            updateCarStatusInfor(1);
//                            finish();

//                            getDataReportData();
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    getDataReportData2();
//                                }
//                            }, 500);//后执行Runnable中的run方法
//                            //新国标升级上传本地后台数据
//                            initJsonDataToPlateform(BaseApplication.W_ItemEnd_time);


                            Toast.makeText(instances, "外检项目完成", Toast
                                    .LENGTH_LONG).show();
                            finish();
//                            EndAllItem(String.valueOf(carsInforModel.getID()));
//                            updateCarStatusInfor(1);
//                            acWaijianBtnWancheng2.setEnabled(true);
//                            Handler handler22 = new Handler();
//                            handler22.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    //项目总结束
////                                updateCarStatusInfor(1);
//                                    EndAllItem(String.valueOf(carsInforModel.getID()));
//                                }
//                            }, 1100);//后执行Runnable中的run方法
                        } else {
                            showDialog("外检平台下线失败，请尝试重新下线");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainEnd-onError==" + response.body());
                        String logStr = "\n" + "外检项目结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //外检上传平台数据
    String upjson_url;

    private void uploadPlatformData_w(final WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
//        if (SharedPreferencesUtils.getCode2List(instances)) {
        if (is_500) {
            upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," + upload_code_str_500 + "," + dbModelData(false, true) + "}]";
        } else {
            upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," + upload_code_str + "," + dbModelData(false, true) + "}]";
        }
//        } else {
//            upjson_url = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," + appendCode2AndValues
//                    () + "," + dbModelData(false, true) + "}]";
//        }

        String logStr = "\n" + "外检上传平台数据--uploadPlatformData_w----json" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) + "" +
                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("uploadPlatformData_w---jsonStr==" + upjson_url);
        UtilsLog.e("uploadPlatformData_w---url==" + SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA).tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("uploadPlatformData_w-result==" + result);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("uploadPlatformData_w-newResult==" + newResult);
                        String logStr = "\n" + "外检上传平台数据--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (newResult.contains("ok") || newResult.contains("OK")) {
                            getDataWaiJainEnd("");

//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//                                    getDataWaiJainEnd("");
//                                }
//                            }, 800);//后执行Runnable中的run方法
                        } else {
                            CommonUtils.hideLoadingDialog(instances);
                            Intent i = new Intent(instances, ErrorMsgActivity.class);
                            i.putExtra("error_msg", result);
                            startActivity(i);

//                            if (gotoTakePhotoCounts3 < 5) {
//                                String logStr2 = "\n" + "外检上传平台次数=循环=" +
//                                        "\n" + "第" + gotoTakePhotoCounts3 + "次" + "\n" + "JSON::" +
//                                        upjson_url + "\n" + "result::" + result;
//                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                                getGET_ALL_ITEMList();
//                                uploadPlatformData_w(waiJainDataModel);
//                                gotoTakePhotoCounts3++;
//                            } else {
//                                CommonUtils.hideLoadingDialog(instances);
//                                String logStr2 = "\n" + "外检上传自己平台次数=循环5次请求失败--没治了=" +
//                                        "\n" + "JSON::" + upjson_url + "\n" +
//                                        "result::" + result;
//                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                                showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
//                            }
//                            showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("uploadPlatformData_w-onError==" + response.body());
                        String logStr = "\n" + "外检上传平台数据-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //组装要上报的json
    private String reportedJsonStr() {
        String myjson = "";
        ReportedModel model;
        model = new ReportedModel();
        model.setDataType("F1");
        model.setDetection_ID(String.valueOf(carsInforModel.getID()));
        model.setGUID(carsInforModel.getGUID());
        model.setTest_times(carsInforModel.getTimes());
        model.setUnqualified_Code1("0");
        model.setUnqualified_Code2("0");
        model.setUnqualified_Code3("0");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
        UtilsLog.e("getDataReportData---myjson==" + myjson);
        return myjson;
    }

    //组装要上报的json
    private String reportedJsonStr3() {
        String myjson = "";
//        ReportedModel3 model;
//        model = new ReportedModel3();
//        model.setDataType("F1");
//        model.setDetection_ID(String.valueOf(carsInforModel.getID()));
////        model.setGUID(carsInforModel.getGUID());
//        model.setTest_times(carsInforModel.getTimes());
        CodeListModel codeListModel = null;
        List<CodeListModel> codeList_list = new ArrayList<>();
        if (BaseApplication.BaseApplication_buHeGeModel3List != null
                && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
            //去重
            Utils.removeDuplicate(BaseApplication.BaseApplication_buHeGeModel3List);
            //set集合保存的是引用不同地址的对象
            Set<BuHeGeModel3> ts = new HashSet<BuHeGeModel3>();
            ts.addAll(BaseApplication.BaseApplication_buHeGeModel3List);

            for (BuHeGeModel3 student : ts) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=去重数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
//                System.out.println(student.getId()+"-"+student.getName());
            }

            //去除  IsCheck==1
            for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=原始数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
                if ("1".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                    BaseApplication.BaseApplication_buHeGeModel3List.remove(i);
                }
            }

            if (BaseApplication.BaseApplication_buHeGeModel3List != null
                    && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
                for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                    UtilsLog.e("BaseApplication_buHeGeModel3List=去掉IsCheck==1后的数据=" +
                            BaseApplication.BaseApplication_buHeGeModel3List.toString());
                    codeListModel = new CodeListModel();
                    codeListModel.setDataType("F1");
                    codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                    codeListModel.setTest_times(carsInforModel.getTimes());
                    if ("0".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                        codeListModel.setUnqualified_Code1(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode1());
                        codeListModel.setUnqualified_Code2(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode2());
                        codeListModel.setUnqualified_Code3(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode3());
                    }
                    codeList_list.add(codeListModel);
                }
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr3333==" + myjson);
            } else {
                codeListModel = new CodeListModel();
                codeListModel.setDataType("F1");
                codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                codeListModel.setTest_times(carsInforModel.getTimes());
                codeListModel.setUnqualified_Code1("0");
                codeListModel.setUnqualified_Code2("0");
                codeListModel.setUnqualified_Code3("0");
                codeList_list.add(codeListModel);
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr4444==" + myjson);
            }
        } else {
            codeListModel = new CodeListModel();
            codeListModel.setDataType("F1");
            codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
            codeListModel.setTest_times(carsInforModel.getTimes());
            codeListModel.setUnqualified_Code1("0");
            codeListModel.setUnqualified_Code2("0");
            codeListModel.setUnqualified_Code3("0");
            codeList_list.add(codeListModel);
            Gson gson = new Gson();
            String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
            myjson = jsonStr;
            UtilsLog.e("reportedJsonStr555==" + myjson);
        }
        return myjson;
    }

    String myjson;

    private void getDataReportData() {
        UtilsLog.e("getDataReportData---url==" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA);
//        myjson = reportedJsonStr();
//        myjson = reportedJsonStr3();
        myjson = reportedJsonStr3("F1", 0);
        String logStr = "\n" + "上传本地数据--getDataReportData--F1--json" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) + "" +
                REPORTED_DATA + "\n" + "JSON::" + myjson + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataReportData-result=myjson=" + myjson);
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(myjson)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData-result==" + result);
                        String logStr = "\n" + "外检上传自己后台数据--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + myjson +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        if ("\"ok\"".equals(result)) {
//                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
//                            instances.finish();
                        } else {
                            if (gotoTakePhotoCounts < 5) {
                                String logStr2 = "\n" + "外检上传自己后台次数=循环=" +
                                        "\n" + "第" + gotoTakePhotoCounts + "次" + "\n" + "JSON::" +
                                        myjson + "\n" + "result::" + result;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                getDataReportData();
                                gotoTakePhotoCounts++;
                            } else {
                                CommonUtils.hideLoadingDialog(instances);
                                String logStr2 = "\n" + "外检上传自己后台次数=循环5次请求失败--没治了=" +
                                        "\n" + "JSON::" + myjson + "\n" +
                                        "result::" + result;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                            }
//                            showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData-onError==" + response.body());
                        UtilsLog.e("getDataReportData-onError==" + response.getException());
                        String logStr = "\n" + "外检上传自己后台数据-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();
                        showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //组装要上报的json
    private String reportedJsonStr3(String dateType, int flag) {
        String myjson = "";
        CodeListModel codeListModel = null;
        List<CodeListModel> codeList_list = new ArrayList<>();
        if (BaseApplication.BaseApplication_buHeGeModel3List != null
                && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
            //去重
            Utils.removeDuplicate(BaseApplication.BaseApplication_buHeGeModel3List);
            //set集合保存的是引用不同地址的对象
            Set<BuHeGeModel3> ts = new HashSet<BuHeGeModel3>();
            ts.addAll(BaseApplication.BaseApplication_buHeGeModel3List);

            for (BuHeGeModel3 student : ts) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=去重数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
//                System.out.println(student.getId()+"-"+student.getName());
            }

            //去除  IsCheck==1
            for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                UtilsLog.e("BaseApplication_buHeGeModel3List=原始数据=" +
                        BaseApplication.BaseApplication_buHeGeModel3List.toString());
                if ("1".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                    BaseApplication.BaseApplication_buHeGeModel3List.remove(i);
                }
            }

            if (BaseApplication.BaseApplication_buHeGeModel3List != null
                    && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
                for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                    UtilsLog.e("BaseApplication_buHeGeModel3List=去掉IsCheck==1后的数据=" +
                            BaseApplication.BaseApplication_buHeGeModel3List.toString());
                    codeListModel = new CodeListModel();
                    codeListModel.setDataType(dateType);
                    codeListModel.setGUID(carsInforModel.getGUID());
                    if (flag == 1) {
                        if (is_db_data) {
                            codeListModel.setF1ResultNote(books.get(0).getF1ResultNote());
                        } else {
                            codeListModel.setF1ResultNote("");
                        }
                    }
                    codeListModel.setTimes(carsInforModel.getTimes());
                    codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                    codeListModel.setTest_times(carsInforModel.getTimes());
                    codeListModel.setStart_Time(my_item_start_time);
                    codeListModel.setFinish_Time(my_item_end_time);
                    if ("0".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                        codeListModel.setUnqualified_Code1(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode1());
                        codeListModel.setUnqualified_Code2(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode2());
                        codeListModel.setUnqualified_Code3(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode3());
                    }
                    codeList_list.add(codeListModel);
                }
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr3333==" + myjson);
            } else {
                codeListModel = new CodeListModel();
                codeListModel.setDataType(dateType);
                codeListModel.setGUID(carsInforModel.getGUID());
                codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                codeListModel.setTest_times(carsInforModel.getTimes());
                codeListModel.setUnqualified_Code1("0");
                codeListModel.setUnqualified_Code2("0");
                codeListModel.setUnqualified_Code3("0");
                codeListModel.setStart_Time(my_item_start_time);
                codeListModel.setFinish_Time(my_item_end_time);
                if (flag == 1) {
                    if (is_db_data) {
                        codeListModel.setF1ResultNote(books.get(0).getF1ResultNote());
                    } else {
                        codeListModel.setF1ResultNote("");
                    }
                }
                codeListModel.setTimes(carsInforModel.getTimes());
                codeList_list.add(codeListModel);
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("reportedJsonStr4444==" + myjson);
            }
        } else {
            codeListModel = new CodeListModel();
            codeListModel.setDataType(dateType);
            codeListModel.setGUID(carsInforModel.getGUID());
            codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
            codeListModel.setTest_times(carsInforModel.getTimes());
            codeListModel.setUnqualified_Code1("0");
            codeListModel.setUnqualified_Code2("0");
            codeListModel.setUnqualified_Code3("0");
            codeListModel.setStart_Time(my_item_start_time);
            codeListModel.setFinish_Time(my_item_end_time);
            if (flag == 1) {
                if (is_db_data) {
                    codeListModel.setF1ResultNote(books.get(0).getF1ResultNote());
                } else {
                    codeListModel.setF1ResultNote("");
                }
            }
            codeListModel.setTimes(carsInforModel.getTimes());
            codeList_list.add(codeListModel);
            Gson gson = new Gson();
            String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
            myjson = jsonStr;
            UtilsLog.e("reportedJsonStr555==" + myjson);
        }
        return myjson;
    }

    String myjson2;

    private void getDataReportData2() {
        UtilsLog.e("getDataReportData2---url==" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA);
        String jsonstr = reportedJsonStr3("F1_Memo", 1);
        myjson2 = "[{" + jsonstr.substring(2, jsonstr.length() - 2) + "," +
                dbModelData(true, false) + "}]";
        UtilsLog.e("getDataReportData2-result=myjson=" + myjson2);
        String logStr = "\n" + "上传本地数据--getDataReportData2--F1_Memo--json" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) + "" +
                REPORTED_DATA + "\n" + "JSON::" + myjson2 + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(myjson2)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData2-result==" + result);
                        String logStr = "\n" + "外检上传自己后台数据--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + myjson2 +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        CommonUtils.hideLoadingDialog(instances);
                        if ("\"ok\"".equals(result)) {

                        } else {
                            if (gotoTakePhotoCounts2 < 5) {
                                String logStr2 = "\n" + "外检上传自己后台次数=循环=" +
                                        "\n" + "第" + gotoTakePhotoCounts2 + "次" + "\n" + "JSON::" +
                                        myjson2 + "\n" + "result::" + result;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                getDataReportData2();
                                gotoTakePhotoCounts2++;
                            } else {
                                CommonUtils.hideLoadingDialog(instances);
                                String logStr2 = "\n" + "外检上传自己后台次数=循环5次请求失败--没治了=" +
                                        "\n" + "JSON::" + myjson2 + "\n" +
                                        "result::" + result;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                                TipDialog.show(instances, "联网项目开始成功", TipDialog.TYPE.WARNING);
//                                MessageDialog.show(instances,  "上传后台数据失败，请重试，如果还未成功请联系管理员", "确定");
                                showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                            }
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData2-onError==" + response.body());
                        UtilsLog.e("getDataReportData2-onError==" + response.getException());
                        String logStr = "\n" + "外检上传自己后台数据-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();
//                        showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }
//    //拼装json  --Code2
//    private String appendCode2AndValues() {
//        String Code2JsonStr = "";
//        String result = "";
//        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
//            for (int i = 0; i < myChoiceModelList.size(); i++) {
//                Code2JsonStr = Code2JsonStr + "\"" + myChoiceModelList.get(i).getCode_key() + "\""
//                        + ":" + "\"" + myChoiceModelList.get(i).getCode_values() + "\"" + ",";
//            }
////            UtilsLog.e("Code2JsonStr==" + Code2JsonStr);
//            UtilsLog.e("Code2JsonStr=22=" + Code2JsonStr.substring(0, Code2JsonStr.length() - 1));
//        }
//        if (Code2JsonStr.length() > 0) {
//            result = Code2JsonStr.substring(0, Code2JsonStr.length() - 1);
//        }
//        return result;
//    }

//    private void getData() {
//        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(instances))) {
//            if (CommonUtils.isOnline(instances)) {
//                getMyCarItems();
//            } else {
//                Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
//                        .LENGTH_LONG).show();
//            }
//        } else {
//            Toast.makeText(instances, "请设置IP与端口号", Toast.LENGTH_LONG).show();
//        }
//    }


    //获取需要检测的人工检验项目接口
    private void getMyCarItems() {
        ItemsModel model = new ItemsModel();
        model.setCarType(carsInforModel.getType());
        model.setDetectCategroy(carsInforModel.getDetectionCategory());
        model.setPassengerNb(carsInforModel.getApprovedLoad());
        model.setPlateType(carsInforModel.getPlateType());

//        String registerTime = carsInforModel.getRegisteDate();
//        String str = registerTime.substring(6, registerTime.length() - 2).trim();
//        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
//        model.setRegisteDate(registerdate);

        model.setSN(carsInforModel.getSN());
        model.setTimes(carsInforModel.getTimes());
        Gson gson = new Gson();
        String json_str = gson.toJson(model);
        UtilsLog.e("getMyCarItems---json_str==" + json_str);
        UtilsLog.e("getMyCarItems---url==" + SharedPreferencesUtils.getIP(this) + GET_MY_ITEM);

        String logStr = "\n" + "外检--获取需要检测的人工检验项目接口--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                GET_MY_ITEM + "\n" + "JSON::" + json_str + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + GET_MY_ITEM).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("getMyCarItems==" + newResult);
                        String logStrf = "\n" + "外检--获取需要检测的人工检验项目接口--onSuccess" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            List<CheckItemModel> DiPanDongTai_checkItemlList = new ArrayList<>();
                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
//                            mycar_checkItemlList = JsonUtil.stringToArray(newResult,
//                                    CheckItemModel[].class);
                            DiPanDongTai_checkItemlList = JsonUtil.stringToArray(newResult,
                                    CheckItemModel[].class);
                            if (DiPanDongTai_checkItemlList != null && DiPanDongTai_checkItemlList.size() > 0) {
                                //给是否拍照列表赋值，初始化
                                for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
                                    IsTakePhoto.add(false);
                                }
                                List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                                Item_2Model item_2 = null;
                                for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
//                                    if (!DiPanDongTai_checkItemlList.get(i).getCode1().equals("6")) {
                                    mycar_checkItemlList.add(DiPanDongTai_checkItemlList.get(i));
                                    if (DiPanDongTai_checkItemlList.get(i).getCode1().equals("3")
                                            || DiPanDongTai_checkItemlList.get(i).getCode1().equals("4")
                                            || DiPanDongTai_checkItemlList.get(i).getCode1().equals("5")) {
                                        item_2 = new Item_2Model();
                                        item_2.setID(DiPanDongTai_checkItemlList.get(i).getID());
                                        item_2.setCode1(DiPanDongTai_checkItemlList.get(i).getCode1());
                                        item_2.setCode2(DiPanDongTai_checkItemlList.get(i).getCode2());
                                        item_2.setName2(DiPanDongTai_checkItemlList.get(i).getName2());
                                        Item_2Model_list.add(item_2);
                                    }
                                }
                                for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                    for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                        if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
                                                .getCode2())) {
                                            Item_2Model_list.remove(j);
                                        }
                                    }
                                }
//                                for (int i = 0; i < mycar_checkItemlList.size(); i++) {
//                                    mycar_checkItemlList.get(i).setFlag("1");
//                                }
                                for (int i = 0; i < myChoiceModelList.size(); i++) {
                                    String Code2 = myChoiceModelList.get(i).getCode2().toString().trim();
                                    for (int j = 0; j < Item_2Model_list.size(); j++) {
                                        String code2_my = Item_2Model_list.get(j).getCode2().toString()
                                                .trim();
                                        if (Code2.equals(code2_my)) {
                                            myChoiceModelList.get(i).setCode_values("1");
                                        }
                                    }
                                }
//
//                                if (myChoiceModelList_waijian != null && myChoiceModelList_waijian.size() > 0) {
//                                    for (int i = 0; i < myChoiceModelList_waijian.size(); i++) {
////                                        UtilsLog.e("myChoiceModelList_waijian==111111=" + myChoiceModelList_waijian.get(i).toString());
//                                        String Code2 = myChoiceModelList_waijian.get(i).getCode2().toString().trim();
//                                        for (int j = 0; j < Item_2Model_list.size(); j++) {
//                                            String code2_my = Item_2Model_list.get(j).getCode2().toString()
//                                                    .trim();
//                                            if (Code2.equals(code2_my)) {
//                                                myChoiceModelList_waijian.get(i).setCode_values(Item_2Model_list.get(j).getFlag());
//                                            }
//                                        }
//                                    }
//                                    upload_code_str = "";
//                                    for (int i = 0; i < myChoiceModelList_waijian.size(); i++) {
//                                        upload_code_str = upload_code_str + "\"" + myChoiceModelList_waijian.get(i).getCode_key() + "\""
//                                                + ":" + "\"" + myChoiceModelList_waijian.get(i).getCode_values() + "\"" + ",";
//                                    }
//                                    if (upload_code_str.length() > 0) {
//                                        upload_code_str = upload_code_str.substring(0, upload_code_str.length() - 1);
//                                    }
//                                    String logStrfw = "\n" + "外检--获取需要检测的人工检验项目接口--upload_code_str" +
//                                            "\n" + "upload_code_str::" + upload_code_str;
//                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
//                                    UtilsLog.e("upload_code_str========" + upload_code_str);
//                                } else {
//                                    UtilsLog.e("myChoiceModelList_waijian=================");
//                                }


                            } else {
                                UtilsLog.e("getMyCarItems-Result==没有获取到当前车辆检测到的项目");
                            }
                        } else {
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                        getMyCarItemsAll();
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getMyCarItems-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "外检--获取需要检测的人工检验项目接口--onError" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }
                });
    }

    private void getMyCarItemsAll() {
        UtilsLog.e("kkkkkkkkkk==" + mycar_checkItemlList.toString());
        String logStr = "\n" + "外检--获取需要检测的人工检验项目接口--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                F1_CODE_ALL + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>get(SharedPreferencesUtils.getIP(this) + F1_CODE_ALL).tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("getMyCarItemsAll==" + newResult);
                        String logStrf = "\n" + "所有--获取需要检测的人工检验项目接口--onSuccess" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
//                            List<CheckItemModel> all_checkItemlList = new ArrayList<>();
//                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
                            myChoiceModelList_waijian_rizhao = new ArrayList<MyChoiceModel>();
                            all_checkItemlList = JsonUtil.stringToArray(newResult,
                                    CheckItemModel[].class);
                            if (all_checkItemlList != null && all_checkItemlList.size() > 0) {
//                                //给是否拍照列表赋值，初始化
//                                for (int i = 0; i < all_checkItemlList.size(); i++) {
//                                    IsTakePhoto.add(false);
//                                }
                                List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                                Item_2Model item_2 = null;
                                for (int i = 0; i < all_checkItemlList.size(); i++) {
                                    for (int j = 0; j < mycar_checkItemlList.size(); j++) {
                                        if (all_checkItemlList.get(i).getCode2().equals(
                                                mycar_checkItemlList.get(j).getCode2())) {
                                            all_checkItemlList.get(i).setFlag("1");
                                            break;
                                        }
                                    }
                                }
                                UtilsLog.e("all_checkItemlList===" + all_checkItemlList.toString());
                                for (int i = 0; i < all_checkItemlList.size(); i++) {
//                                    UtilsLog.e("all_checkItemlList==="+all_checkItemlList.get(i).toString());
                                    item_2 = new Item_2Model();
                                    item_2.setID(all_checkItemlList.get(i).getID());
                                    item_2.setCode1(all_checkItemlList.get(i).getCode1());
                                    item_2.setCode2(all_checkItemlList.get(i).getCode2());
                                    item_2.setName2(all_checkItemlList.get(i).getName2());
//                                    if (TextUtils.isEmpty(all_checkItemlList.get(i).getFlag())) {
//                                        item_2.setFlag("0");
//                                    } else {
//                                        item_2.setFlag("1");
//                                    }
                                    item_2.setFlag(all_checkItemlList.get(i).getFlag());
                                    Item_2Model_list.add(item_2);
                                }
                                for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                    for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                        if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
                                                .getCode2())) {
                                            Item_2Model_list.remove(j);
                                        }
                                    }
                                }

                                for (int i = 0; i < Item_2Model_list.size(); i++) {
                                    MyChoiceModel model = new MyChoiceModel();
                                    model.setCode2(Item_2Model_list.get(i).getCode2());
                                    model.setChecked(true);
                                    model.setName2(Item_2Model_list.get(i).getName2());
                                    model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                                    model.setCode_values(Item_2Model_list.get(i).getFlag());
                                    myChoiceModelList_waijian_rizhao.add(model);
                                }
                                if (myChoiceModelList_waijian_rizhao != null && myChoiceModelList_waijian_rizhao.size() > 0) {
                                    for (int i = 0; i < myChoiceModelList_waijian_rizhao.size(); i++) {
                                        String Code2 = myChoiceModelList_waijian_rizhao.get(i).getCode2().toString().trim();
                                        for (int j = 0; j < Item_2Model_list.size(); j++) {
                                            String code2_my = Item_2Model_list.get(j).getCode2().toString()
                                                    .trim();
                                            if (Code2.equals(code2_my)) {
                                                myChoiceModelList_waijian_rizhao.get(i).setCode_values(Item_2Model_list.get(j).getFlag());
                                            }
                                        }
                                    }


                                    upload_code_str = "";
                                    for (int i = 0; i < myChoiceModelList_waijian_rizhao.size(); i++) {
                                        upload_code_str = upload_code_str + "\"" + myChoiceModelList_waijian_rizhao.get(i).getCode_key() + "\""
                                                + ":" + "\"" + myChoiceModelList_waijian_rizhao.get(i).getCode_values() + "\"" + ",";
                                        String Code2 = myChoiceModelList_waijian_rizhao.get(i).getCode2().toString().trim();
                                        for (int j = 0; j < all_checkItemlList.size(); j++) {
                                            if (Code2.equals(all_checkItemlList.get(j).getCode2())) {
                                                all_checkItemlList.get(j).setFlag(myChoiceModelList_waijian_rizhao.get(i).getCode_values());
                                                break;
                                            }
                                        }
                                    }

                                    UtilsLog.e("myChoiceModelList_waijian_rizhao==111111=" + myChoiceModelList_waijian_rizhao.toString());
                                    UtilsLog.e("myChoiceModelList_waijian_rizhao==222222=" + all_checkItemlList.toString());
                                    if (upload_code_str.length() > 0) {
                                        upload_code_str = upload_code_str.substring(0, upload_code_str.length() - 1);
                                    }
                                    String logStrfw = "\n" + "所有--获取需要检测的人工检验项目接口--upload_code_str" +
                                            "\n" + "upload_code_str::" + upload_code_str;
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                                    UtilsLog.e("upload_code_str========" + upload_code_str);
                                } else {
                                    UtilsLog.e("所有myChoiceModelList_waijian=================");
                                }
                            } else {
                                UtilsLog.e("所有getMyCarItems-Result==没有获取到当前车辆检测到的项目");
                            }
                        } else {
                            UtilsLog.e("所有getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("所有getMyCarItems-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "所有--获取需要检测的人工检验项目接口--onError" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }
                });
    }

    //视频接口
    private void uploadVideo(VideoModel model) {

//        BaseApplication.W_ItemStart_time = DateUtil.currentTime2();
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        UtilsLog.e("uploadVideo---jsonStr==" + jsonStr);
        UtilsLog.e("uploadVideo---url==" + SharedPreferencesUtils.getIP(this) + VIDEO_ITEM);
        String logStr = "\n" + "外检--uploadVideo--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                VIDEO_ITEM + "\n" + "JSON::" + jsonStr + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + VIDEO_ITEM).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("uploadVideo-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "外检--uploadVideo--请求成功" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("uploadPlatformData_w-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                        String logStr = "\n" + "外检--uploadVideo-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                VIDEO_ITEM + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    //获取某辆车的外检拍照的项目
    // PlateType,CarType,Usage
    String json_str_getOutPhotoItem;

    private void getOutPhotoItem() {
        OutPhotoItem model = new OutPhotoItem();
//        model.setCarType(carsInforModel.getType());
//        model.setPlateType(carsInforModel.getPlateType());
//        model.setUsage(carsInforModel.getUsage());
//        model.setPlatformSN(carsInforModel.getPlatformSN());
        model.setSN(carsInforModel.getSN());
        model.setTimes(carsInforModel.getTimes());
        Gson gson = new Gson();
        json_str_getOutPhotoItem = gson.toJson(model);
        UtilsLog.e("getOutPhotoItem---json_str==" + json_str_getOutPhotoItem);
        UtilsLog.e("getOutPhotoItem---url==" + SharedPreferencesUtils.getIP(this) + WAI_JIAN_PHOTO_ITEM);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + WAI_JIAN_PHOTO_ITEM).tag(this)
                .upJson(json_str_getOutPhotoItem)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        BaseApplication.msg = result;
//                        UtilsLog.e("getOutPhotoItem-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String newResult = result;
                        UtilsLog.e("getOutPhotoItem-newResult==" + newResult);

                        String logStr = "\n" + "外检--获取某辆车的外检拍照的项目--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                WAI_JIAN_PHOTO_ITEM + "\n" + "JSON::" + json_str_getOutPhotoItem +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {

                            typeModelList = JsonUtil.stringToArray(newResult, TypeModel[].class);
                            if (typeModelList != null && typeModelList.size() > 0) {
                                TypeModel typeModel = null;
                                for (int i = 0; i < typeModelList.size(); i++) {
                                    typeModel = new TypeModel();
                                    typeModel.setName(typeModelList.get(i).getName());
                                    typeModel.setCode(typeModelList.get(i).getCode());
                                    typeModelListAdapter.add(typeModel);
                                }
                                contentAdapter2 = new ContentAdapter2(instances, typeModelListAdapter,
                                        mListener, instances);
                                //实例化ContentAdapter2类，并传入实现类
                                acWaijianPhotoListview.setAdapter(contentAdapter2);
                                setListViewHeightBasedONChildren(acWaijianPhotoListview);
                                acWaijianPhotoListview.setOnItemClickListener(instances);
                            }
                        } else {
                            String logStr2 = "\n" + "外检--获取某辆车的外检拍照的项目--失败" +
                                    "\n" + "result::" + result;
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                            BaseApplication.msg = result;
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        BaseApplication.msg = response.body() + "==" + response.message();
                        UtilsLog.e("getOutPhotoItem-onError==" + response.body());
                        String logStr = "\n" + "外检--获取某辆车的外检拍照的项目-onError" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                WAI_JIAN_PHOTO_ITEM + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    /**
     * 项目总结束接口,最后一个执行
     */
    private void EndAllItem(final String detectionID) {
        UtilsLog.e("EndAllItem---url==" + SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID");
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID").tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        //完成按钮可点击
//                        acWaijianBtnWancheng2.setEnabled(true);

                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        UtilsLog.e("EndAllItem-result==" + result);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        finish();

//                        if ("\"ok\"".equals(result)) {
//
//                            updateCarStatusInfor(1);
//                            Toast.makeText(instances, "外检项目完成", Toast
//                                    .LENGTH_LONG).show();
//
//                        } else {
//                            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr = "\n" + "外检项目总结束:总结束:总结束-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_ALL_END + detectionID + "/DetectionID" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("EndAllItem-onError==" + response.body());
                        UtilsLog.e("EndAllItem-onError==" + response.getException());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    public static void setListViewHeightBasedONChildren(ListView listView) {
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0; i < listAdapter.getCount(); i++) {
            View listItem = listAdapter.getView(i, null, listView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        listView.setLayoutParams(params);

    }

    private List<TypeModel> typeModelList;
    private List<TypeModel> typeModelListAdapter;
    private ContentAdapter2 contentAdapter2;

    private void init() {
        typeModelList = new ArrayList<>();
        typeModelListAdapter = new ArrayList<>();
    }

    //响应item点击事件
    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
//        Toast.makeText(this, "listview的item被点击了！，点击的位置是-->" + position,
//                Toast.LENGTH_SHORT).show();
    }

    /**
     * 实现类，响应按钮点击事件
     */
    TypeModel typeModel;
    int TypeModel_Position = 0;
    private String img_imageUri_path;
    private ContentAdapter2.MyClickListener mListener = new ContentAdapter2.MyClickListener() {
        @Override
        public void myOnClick(int position, View v, int flag) {
            PHOTO_TYPE = typeModelListAdapter.get(position).getCode();
            TypeModel_Position = position;
            FLAG = flag;
            if (flag == 0) {
//                //跳转到图片预览界面
//                if (WAIJIAN_PHOTO_PREVIEW_LISTS.get(Integer.parseInt(PHOTO_TYPE)) != null) {
//                    Intent intent_preview = new Intent(instances, PhotoPreviewActivity.class);
//                    intent_preview.putExtra("key_integer", Integer.parseInt(PHOTO_TYPE));
//                    startActivity(intent_preview);
//                }

                //相册
                takePhoto = getTakePhoto();
                File file = new File(Environment.getExternalStorageDirectory(), "/temp_my_app/" + System
                        .currentTimeMillis() + ".jpg");
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                imageUri = Uri.fromFile(file);
                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=7777=" + imageUri);
                img_imageUri_path = imageUri.getPath();
                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=888=" + imageUri.getPath());
                takePhoto.onPickFromDocuments();
                typeModel = new TypeModel();
                typeModel.setName(typeModelListAdapter.get(position).getName());
                typeModel.setCode(typeModelListAdapter.get(position).getCode());


            } else if (flag == 1) {
//                takePicture();
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//                    takePicture();
//                } else {
                Log.e("photo", "takePhoto---takePhoto");
                takePhoto = getTakePhoto();
                TakePhotoOptions takePhotoOptions = new TakePhotoOptions.Builder().setCorrectImage(false).create();
                takePhoto.setTakePhotoOptions(takePhotoOptions);
//                    configCompress(takePhoto);
//                    File file = new File(Environment.getExternalStorageDirectory(), "/temp_my_app/" + System
//                            .currentTimeMillis() + ".jpg");
                File file = new File(Environment.getExternalStorageDirectory(), "/temp_my_app/" + System
                        .currentTimeMillis() + ".jpg");
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                imageUri = Uri.fromFile(file);
                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=7777=" + imageUri);
                img_imageUri_path = imageUri.getPath();
                UtilsLog.e("photo", "WAIJIAN_PHOTO_imageUri=888=" + imageUri.getPath());
                takePhoto.onPickFromCapture(imageUri);
//                }
                typeModel = new TypeModel();
                typeModel.setName(typeModelListAdapter.get(position).getName());
                typeModel.setCode(typeModelListAdapter.get(position).getCode());
            } else if (flag == 2) {
                //跳转到图片预览界面
                if (WAIJIAN_PHOTO_PREVIEW_LISTS.get(Integer.parseInt(PHOTO_TYPE)) != null) {
                    Intent intent_preview = new Intent(instances, PhotoPreviewActivity.class);
                    intent_preview.putExtra("key_integer", Integer.parseInt(PHOTO_TYPE));
                    startActivity(intent_preview);
                }
            }

//            Toast.makeText(
//                    Main2Activity.this,
//                    "listview的内部的按钮被点击了！，位置是-->" + position + ",内容是-->"
//                            + typeModelList.get(position).getMsg() + ",flag是-->" + flag, Toast.LENGTH_SHORT)
//                    .show();
        }
    };

    /**
     * 更新车辆状态
     *
     * @param flag flag:0 未检测
     * flag:1 项目开始
     * flag:2 项目结束
     * flag:917  中途退出的情况
     */
    String jsonStr22;

    public void updateCarStatusInfor(int flag) {
        UpdateCarStatusModel model = new UpdateCarStatusModel();
        model.setType(0);
        model.setQueueID(String.valueOf(carsInforModel.getID()));
        switch (CHECK_MODE) {
            case 0:
                model.setAppearanceStatus(flag);
                break;
            case 1:
                model.setRoadStatus(flag);
                break;
            case 2:
                model.setDynamicStatus(flag);
                break;
        }
        Gson gson = new Gson();
        jsonStr22 = gson.toJson(model);
        UtilsLog.e("updateCarStatusInfor---jsonStr==" + jsonStr22);
        UtilsLog.e("updateCarStatusInfor---url==" + SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS)
                .tag(this)
                .upJson(jsonStr22)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("updateCarStatusInfor-result==" + result);
                        UtilsLog.e("updateCarStatusInfor-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "外检项目更新状态--请求成功--onSuccess" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "JSON::" + jsonStr22 + "\n" + "result::" +
                                response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        String logStr = "\n" + "外检项目更新状态-onError" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            String logStr = "\n" + "外检--返回键-屏幕底部" + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//            updateCarStatusInfor(ITEM_MIDDLE_EXIT_CODE);
            finish();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    android.support.v7.app.AlertDialog.Builder builder = null;

    private void showDialog(String content) {
        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder
                (instances);
        builder.setTitle("提示");
        builder.setMessage(content);
//        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", null);
        builder.show();
    }


    List<MyChoiceModel> myChoiceModelList_waijian = new ArrayList<>();//Code2选择的列表

    //    List<MyChoiceModel> myChoiceModelList_waijian_rizhao = new ArrayList<>();//Code2选择的列表
    //拼装json  --Code2
    private String appendCode2AndValues() {
        String Code2JsonStr = "";
        String result = "";
        if (myChoiceModelList_waijian != null && myChoiceModelList_waijian.size() > 0) {
            for (int i = 0; i < myChoiceModelList_waijian.size(); i++) {
                UtilsLog.e("Code2JsonStr=22=myChoiceModelList==22222222222222=" + myChoiceModelList_waijian.get(i).toString());
                Code2JsonStr = Code2JsonStr + "\"" + myChoiceModelList_waijian.get(i).getCode_key() + "\""
                        + ":" + "\"" + myChoiceModelList_waijian.get(i).getCode_values() + "\"" + ",";
            }
//            UtilsLog.e("Code2JsonStr==" + Code2JsonStr);
            UtilsLog.e("Code2JsonStr=22=" + Code2JsonStr.substring(0, Code2JsonStr.length() - 1));
        } else {
            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
            bb();
            UtilsLog.e("Code2JsonStr=22=nullll");
        }
        if (Code2JsonStr.length() > 0) {
            result = Code2JsonStr.substring(0, Code2JsonStr.length() - 1);
        }
//        UtilsLog.e("Code2JsonStr=22=appendCode2AndValues---------------------000000");
        UtilsLog.e("Code2JsonStr=22=appendCode2AndValues-----000000==" + result);
        return result;
    }

    String dbModelData(boolean is, boolean f1_resul_tnote) {
        String result = "";
        Gson gson = new Gson();
        WaiJianItemModel model = null;
        WaiJainDataModel waiJainDataModel = null;
        if (is_db_data) {
            model = new WaiJianItemModel();
            waiJainDataModel = new WaiJainDataModel();
            model = books.get(0);
            UtilsLog.e("model==" + model.toString());
            waiJainDataModel.setRemark(model.getRemark());
            //转向轴数量
            waiJainDataModel.setTurnAxis(model.getZhuanxiangzhou());
//            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTurnAxis()))) {
//                waiJainDataModel.setTurnAxis(carsInforModel.getTurnAxis());
//            }
            //驻车制动是否使用电子控制装置
//            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getElectronicHandbrake()))) {
//                waiJainDataModel.setElectronicHandbrake(
//                        carsInforModel.getElectronicHandbrake().equals("1") ? "1" : "0");
//            }
            waiJainDataModel.setElectronicHandbrake(model.getShifouDianzikongzhi());
            waiJainDataModel.setAirSuspension(model.getKongqiXuanjia());
//            if (model.getShifouDianzikongzhi().contains("是")) {
//                waiJainDataModel.setElectronicHandbrake("1");
//            } else {
//                waiJainDataModel.setElectronicHandbrake("0");
//            }
//            if (model.getKongqiXuanjia().contains("是")) {
//                waiJainDataModel.setAirSuspension("1");
//            } else {
//                waiJainDataModel.setAirSuspension("0");
//            }

            //空气悬架轴
//            waiJainDataModel.setAirSuspensionAxle(carsInforModel.getAirSuspensionAxle());
            waiJainDataModel.setAirSuspensionAxle(model.getKongqiXuanjiaZhou());
            //是否配备空气悬架
//            waiJainDataModel.setAirSuspension(carsInforModel.getAirSuspension().equals("1") ? "1" : "0");
//            waiJainDataModel.setAirSuspension(model.getKongqiXuanjiaZhou());
            if (is) {
                //是否全时/适时四驱
//                if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getDriverType()))) {
//                    waiJainDataModel.setDriverType(carsInforModel.getDriverType());
//                }
//                waiJainDataModel.setDriverType(model.getShifouQuanshi());
                if (model.getShifouQuanshi().equals("是")||model.getShifouQuanshi().contains("1")) {
                    waiJainDataModel.setDriverType("1");
                } else {
                    waiJainDataModel.setDriverType("0");
                }
            } else {
                if (model.getShifouQuanshi().equals("是")||model.getShifouQuanshi().contains("1")) {
                    waiJainDataModel.setDriverType("1");
                } else {
                    waiJainDataModel.setDriverType("0");
                }
            }
            if (model.getShifouQuanshi().equals("是")||model.getShifouQuanshi().contains("1")) {
                waiJainDataModel.setFourWheelDrive("1");
            } else {
                waiJainDataModel.setFourWheelDrive("0");
            }
            waiJainDataModel.setWKLength(model.getWaikuoChang());
            waiJainDataModel.setWKWidth(model.getWaikuoKuan());
            waiJainDataModel.setWKHeight(model.getWaikuoGao());
            waiJainDataModel.setDLiftHeight(model.getChexiangLanbanGaodu());
            waiJainDataModel.setTurnTireTreadDepth(model.getDancheZhuanxianglunLuntaiHuawenShendu());
            waiJainDataModel.setOtherTireTreadDepth(model.getDancheQtaLuntaiHuawenShendu());
            waiJainDataModel.setGLiftHeight(model.getGuaCheLanbanGaodu());
            waiJainDataModel.setGTireTreadDepth(model.getGuacheLuntaiHuanwenShendu());
            waiJainDataModel.setFirstAxisLeftHeight(model.getDiyizhouZuogaodu());
            waiJainDataModel.setFirstAxisRightHeight(model.getDiyizhouYougaodu());
            waiJainDataModel.setFirstAxisHeightDiff(model.getDiyizhouZuoyouGaodu());
            waiJainDataModel.setLastAxisLeftHeight(model.getZuihouzhouZuoGaodu());
            waiJainDataModel.setLastAxisRightHeight(model.getZuihouzhouYouGaodu());
            waiJainDataModel.setLastAxisHeightDiff(model.getZuihouzhouZuoyouGaodu());
            waiJainDataModel.setGAxisLeftHeight(model.getGuaCheZuoGaodu());
            waiJainDataModel.setGAxisRightHeight(model.getGuaCheYouGaodu());
            waiJainDataModel.setGAxisHeightDiff(model.getGuaCheGaoduGaoducha());
            waiJainDataModel.setWheelBase(model.getZhouju());
            if (f1_resul_tnote) {
                waiJainDataModel.setF1ResultNote(model.getF1ResultNote());
            } else {

            }
            result = gson.toJson(waiJainDataModel);
        } else {
            waiJainDataModel = new WaiJainDataModel();
            waiJainDataModel.setRemark("");
            //转向轴数量
            waiJainDataModel.setTurnAxis("0");
//            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTurnAxis()))) {
//                waiJainDataModel.setTurnAxis("0");
//            }
            //驻车制动是否使用电子控制装置
//            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getElectronicHandbrake()))) {
//                waiJainDataModel.setElectronicHandbrake(
//                        carsInforModel.getElectronicHandbrake().equals("1") ? "1" : "0");
//            }
//            //空气悬架轴
//            waiJainDataModel.setAirSuspensionAxle(carsInforModel.getAirSuspensionAxle());
//            //是否配备空气悬架
//            waiJainDataModel.setAirSuspension(carsInforModel.getAirSuspension().equals("1") ? "1" : "0");

            waiJainDataModel.setElectronicHandbrake("0");
            //空气悬架轴
//            waiJainDataModel.setAirSuspensionAxle(carsInforModel.getAirSuspensionAxle());
            waiJainDataModel.setAirSuspensionAxle("0");
            //是否配备空气悬架
//            waiJainDataModel.setAirSuspension(carsInforModel.getAirSuspension().equals("1") ? "1" : "0");
            waiJainDataModel.setAirSuspension("0");

            if (is) {
                //是否全时/适时四驱
//                if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getDriverType()))) {
//                    waiJainDataModel.setDriverType(carsInforModel.getDriverType());
//                }
                waiJainDataModel.setDriverType("0");
            } else {
                waiJainDataModel.setDriverType("0");
            }
            waiJainDataModel.setWKLength("");
            waiJainDataModel.setWKWidth("");
            waiJainDataModel.setWKHeight("");
            waiJainDataModel.setDLiftHeight("");
            waiJainDataModel.setTurnTireTreadDepth("");
            waiJainDataModel.setOtherTireTreadDepth("");
            waiJainDataModel.setGLiftHeight("");
            waiJainDataModel.setGTireTreadDepth("");
            waiJainDataModel.setFirstAxisLeftHeight("");
            waiJainDataModel.setFirstAxisRightHeight("");
            waiJainDataModel.setFirstAxisHeightDiff("");
            waiJainDataModel.setLastAxisLeftHeight("");
            waiJainDataModel.setLastAxisRightHeight("");
            waiJainDataModel.setLastAxisHeightDiff("");
            waiJainDataModel.setGAxisLeftHeight("");
            waiJainDataModel.setGAxisRightHeight("");
            waiJainDataModel.setGAxisHeightDiff("");
            waiJainDataModel.setWheelBase("");
            if (f1_resul_tnote) {
                waiJainDataModel.setF1ResultNote("");
            } else {

            }
            //是否全时/适时四驱
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getDriverType()))) {
                if (carsInforModel.getDriverType().equals("2") || carsInforModel.getDriverType().equals("3")) {
                    waiJainDataModel.setFourWheelDrive("1");
                } else {
                    waiJainDataModel.setFourWheelDrive("0");
                }
            }
            result = gson.toJson(waiJainDataModel);
        }
//        UtilsLog.e("dbModelData---json==" + result);
//        UtilsLog.e("dbModelData---json=111=" + result.substring(1, result.length() - 1));
        return result.substring(1, result.length() - 1);
    }

    //上传本地后台
    private void uploadData(WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
        UtilsLog.e("外检项目--上传本地后台数据---jsonStr==" + jsonStr);
        UtilsLog.e("外检项目--上传本地后台数据---url==" + SharedPreferencesUtils.getIP(this) + REPORTED_DATA);
        String logStr = "\n" + "外检项目--上传本地后台数据---json" + "\n" +
                "json::" + jsonStr + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + REPORTED_DATA).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("外检项目--上传本地后台数据--result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("外检项目--上传本地后台数据--newResult==" + newResult);
                        String logStr = "\n" + "外检项目--上传本地后台数据---请求成功" +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        if ("ok".equalsIgnoreCase(newResult)) {
////                            Handler handler = new Handler();
////                            handler.postDelayed(new Runnable() {
////                                @Override
////                                public void run() {
////                                    updateCarStatusInfor();
////                                }
////                            }, 800);//后执行Runnable中的run方法
//                        } else {
//                            showDialog("上传本地后台数据失败，请重试");
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("外检项目--上传后台数据-onError==" + response.body());
                        String logStr = "\n" + "外检项目--上传本地后台数据--onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        showDialog("上传本地后台数据网络异常，请重试");
                    }
                });
    }

    void initJsonDataToPlateform(String finish_time) {
        waiJainDataModel2.setDetection_ID(String.valueOf(carsInforModel.getID()));
        waiJainDataModel2.setGUID(carsInforModel.getGUID());
        waiJainDataModel2.setDetectionDevID(SharedPreferencesUtils.getIMEI(this));
        waiJainDataModel2.setBrakeForce(carsInforModel.getBrakeForce());
        waiJainDataModel2.setPlateNO(carsInforModel.getPlateNO());
        waiJainDataModel2.setAirAdmission(carsInforModel.getAirAdmission());
        try {
            String name = URLDecoder.decode(Login_name, "UTF-8");
            waiJainDataModel2.setAppearanceInspector(name);//检测员名字，汉字
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        waiJainDataModel2.setAppearanceNo(login_IDNumber);
        waiJainDataModel2.setApprovedLoad(carsInforModel.getApprovedLoad());
        waiJainDataModel2.setArea(carsInforModel.getArea());
        waiJainDataModel2.setBodyColor(carsInforModel.getBodyColor());
        waiJainDataModel2.setBrand(carsInforModel.getBrand());
        waiJainDataModel2.setCarBodyType(carsInforModel.getCarBodyType());
        waiJainDataModel2.setCarID(carsInforModel.getCarID());
        waiJainDataModel2.setCarModel(carsInforModel.getCarModel());
        waiJainDataModel2.setCarTypeLevel(carsInforModel.getCarTypeLevel());
        waiJainDataModel2.setCategory(carsInforModel.getCategory());
        waiJainDataModel2.setCentralAxle(carsInforModel.getCentralAxle());
        waiJainDataModel2.setCode(carsInforModel.getCode());
        waiJainDataModel2.setCombCarNO(carsInforModel.getCombCarNO());
        waiJainDataModel2.setCurbWeight(carsInforModel.getCurbWeight());
        waiJainDataModel2.setDetectDate(carsInforModel.getDetectDate());
        waiJainDataModel2.setDetectionCategory(carsInforModel.getDetectionCategory());
        waiJainDataModel2.setDetectionStatus(carsInforModel.getDetectionStatus());
        waiJainDataModel2.setDisplacement(carsInforModel.getDisplacement());
        waiJainDataModel2.setDriveAxle(carsInforModel.getDriveAxle());
        waiJainDataModel2.setDriverAxleWeight(carsInforModel.getDriverAxleWeight());
        waiJainDataModel2.setDriverTypeName(carsInforModel.getDriverTypeName());
        waiJainDataModel2.setDriverType(carsInforModel.getDriverType());
        waiJainDataModel2.setPlateType(carsInforModel.getPlateType());
        waiJainDataModel2.setItemcode(Item_Code);
        waiJainDataModel2.setLine(Line);
        waiJainDataModel2.setMainAxis(carsInforModel.getMainAxis());
        waiJainDataModel2.setParkingAxle(carsInforModel.getParkingAxle());
        waiJainDataModel2.setEngineNO(carsInforModel.getEngineNO());
        waiJainDataModel2.setFuelType(carsInforModel.getFuelType());
        waiJainDataModel2.setPlateTypeName(carsInforModel.getPlateTypeName());
        waiJainDataModel2.setPlatformSN(carsInforModel.getPlatformSN());
        waiJainDataModel2.setQueueID(carsInforModel.getQueueID());
        waiJainDataModel2.setSN(carsInforModel.getSN());
        waiJainDataModel2.setStatus(carsInforModel.getStatus());
        waiJainDataModel2.setTest_times(carsInforModel.getTimes());
        waiJainDataModel2.setTimes(carsInforModel.getTimes());
        waiJainDataModel2.setType(carsInforModel.getType());
        waiJainDataModel2.setVIN(carsInforModel.getVIN());
        waiJainDataModel2.setDataType(Item_Code);
        waiJainDataModel2.setOwner(carsInforModel.getOwner());
        waiJainDataModel2.setTelephone(carsInforModel.getTelephone());
        waiJainDataModel2.setAddress(carsInforModel.getAddress());
        waiJainDataModel2.setStart_Time(my_item_start_time);
        waiJainDataModel2.setFinish_Time(finish_time);

        List<WaiJianItemModel> books = WaiJianItemModel.listAll(WaiJianItemModel.class);
        if (books != null && books.size() > 0) {
            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询--2222--不为空==" + books.toString());
            for (int i = 0; i < books.size(); i++) {
                waiJainDataModel2.setWKLength(books.get(i).getWaikuoChang());
                waiJainDataModel2.setWKHeight(books.get(i).getWaikuoGao());
                waiJainDataModel2.setWKWidth(books.get(i).getWaikuoKuan());
                waiJainDataModel2.setWBase(books.get(i).getZhouju());
                waiJainDataModel2.setTurnTireTreadDepth(books.get(i).getDancheZhuanxianglunLuntaiHuawenShendu());
                waiJainDataModel2.setOtherTireTreadDepth(books.get(i).getDancheQtaLuntaiHuawenShendu());
                waiJainDataModel2.setGTireTreadDepth(books.get(i).getGuacheLuntaiHuanwenShendu());
                waiJainDataModel2.setDLiftHeight(books.get(i).getChexiangLanbanGaodu());
                waiJainDataModel2.setGLiftHeight(books.get(i).getGuaCheLanbanGaodu());
                waiJainDataModel2.setFirstAxisLeftHeight(books.get(i).getDiyizhouZuogaodu());
                waiJainDataModel2.setFirstAxisRightHeight(books.get(i).getDiyizhouYougaodu());
                waiJainDataModel2.setFirstAxisHeightDiff(books.get(i).getDiyizhouZuoyouGaodu());
                waiJainDataModel2.setLastAxisLeftHeight(books.get(i).getZuihouzhouZuoGaodu());
                waiJainDataModel2.setLastAxisRightHeight(books.get(i).getZuihouzhouYouGaodu());
                waiJainDataModel2.setLastAxisHeightDiff(books.get(i).getZuihouzhouZuoyouGaodu());
                waiJainDataModel2.setGAxisLeftHeight(books.get(i).getGuaCheZuoGaodu());
                waiJainDataModel2.setGAxisRightHeight(books.get(i).getGuaCheYouGaodu());
                waiJainDataModel2.setGAxisHeightDiff(books.get(i).getGuaCheGaoduGaoducha());
            }
        } else {
            UtilsLog.e("WaiJianPhotoActivity----本地数据库查询--2222--空==");
        }


        uploadData(waiJainDataModel2);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
        UtilsLog.e("外检----请求拍照权限成功===");
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        UtilsLog.e("外检----请求拍照权限失败===");
    }
}
